package org.rasterfun.language2

/**
 * 
 * 
 * @author Hans Haggstrom
 */
class Context {
  var variables: List[String] = Nil
  private var nextFreeVariableNum = 1

  def addVariable(expr: String): String = {
    // TODO: Also determine variable type
    val name = "variable_" + nextFreeVariableNum
    val kind = "float"
    variables = variables ::: List("final "+kind+" "+name+" = "+expr+" ;\n")
    nextFreeVariableNum = nextFreeVariableNum + 1
    name
  }

  def generateCode(source: StringBuilder) {
    source.append("// context\n")
    source.append(variables.mkString)
  }

  override def toString = variables.mkString
}

